package admin.point;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import admin.point.PointStatusVO;

import org.apache.struts2.interceptor.SessionAware;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class PointManagement extends ActionSupport { 
	public static Reader reader; 
	public static SqlMapClient sqlMapper;
	
	private PointStatusVO ps_paramClass = new PointStatusVO();
	private PointStatusVO ps_resultClass = new PointStatusVO();
	
	private List<PointStatusVO> ps_list=new ArrayList<PointStatusVO>();
	
	private int no;
	private int join_points;
	private int event_points;
	private int total_points;
	private int total_price;
	private String pay_way;
	
	Calendar today = Calendar.getInstance();
	
	public PointManagement() throws IOException {
		reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();
	}
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	public String pointStatus() throws Exception {
		ps_list = sqlMapper.queryForList("nowPointStatus");
		
		ps_resultClass = (PointStatusVO)sqlMapper.queryForObject("selectPointStatus",ps_list.size());
		//System.out.println(ps_resultClass.getEvent_points());
		return SUCCESS;
	}
	public String updatePointStatus() throws Exception {
		ps_list = sqlMapper.queryForList("nowPointStatus");
		
		ps_paramClass.setNo(getNo());
		ps_paramClass.setJoin_points(getJoin_points());
		ps_paramClass.setEvent_points(getEvent_points());
		ps_paramClass.setPay_way(getPay_way());
		//System.out.println(ps_list.size());
		if(ps_list.size() < 1){
			sqlMapper.insert("insertPointStatus", ps_paramClass);
		}else{
			sqlMapper.update("updatePointStatus", ps_paramClass);
		}
		return SUCCESS;
	}
	
	public PointStatusVO getPs_paramClass() {
		return ps_paramClass;
	}
	public void setPs_paramClass(PointStatusVO ps_paramClass) {
		this.ps_paramClass = ps_paramClass;
	}
	public PointStatusVO getPs_resultClass() {
		return ps_resultClass;
	}
	public void setPs_resultClass(PointStatusVO ps_resultClass) {
		this.ps_resultClass = ps_resultClass;
	}
	public List<PointStatusVO> getPs_list() {
		return ps_list;
	}
	public void setPs_list(List<PointStatusVO> ps_list) {
		this.ps_list = ps_list;
	}
	public int getNo() {
		return no;
	}
	public void setNo(int no) {
		this.no = no;
	}
	public int getJoin_points() {
		return join_points;
	}
	public void setJoin_points(int join_points) {
		this.join_points = join_points;
	}
	public int getEvent_points() {
		return event_points;
	}
	public void setEvent_points(int event_points) {
		this.event_points = event_points;
	}
	public int getTotal_points() {
		return total_points;
	}
	public void setTotal_points(int total_points) {
		this.total_points = total_points;
	}
	public int getTotal_price() {
		return total_price;
	}
	public void setTotal_price(int total_price) {
		this.total_price = total_price;
	}
	public String getPay_way() {
		return pay_way;
	}
	public void setPay_way(String pay_way) {
		this.pay_way = pay_way;
	}
}
